(function(vc) {

    vc.extends({
        data: {
            homePageInfo: {
                informations: [],
                prodClasses: [],
            },
            userInfo: {
                storeTypeCd: "",
                name: "",
                tel: "",
                levelCd: "",
                userId: "" ,
                cartProducts:[]
            },
        },
        _initMethod: function() {
            $that._loadInformations();
            let _getUserInfo = vc.getData('/nav/getUserInfo')
            if(_getUserInfo) {
                $that.getUserInfo();
            }
            $that.websiteAccessLog();
        },
        _initEvent: function() {
            $(window).scroll(function(){
                var topH=$(".header").height()+$(".banner").height();
                var footH=$(document).height()-$(".footer").height()-500;
                if($(this).scrollTop()>topH-250 && $(this).scrollTop()<=footH){
                    $(".leftgood-bar").fadeIn(200);
                }else{
                    $(".leftgood-bar").fadeOut(200);
                }
            });
            setLeftBar();
            function setLeftBar(){
                if($(window).width()>1800){
                    $(".leftgood-bar").css("left",'250px');
                }
                if($(window).width()<=1800){
                    $(".leftgood-bar").css("left",'120px');
                }
                if($(window).width()<1600){
                    $(".leftgood-bar").css("left",'0px');
                }
            }
            $(window).resize(function(){
                setLeftBar();
            });
            $(".leftgood-bar .lgb").each(function(){
                $(this).click(function(){
                    $("body ,html").animate({scrollTop: $($(this).find("a").attr("name")).offset().top}, 500);
                });
            });
            $(window).scroll(function(){
                var scrollTop=$(window).scrollTop();
                var len = $(".leftgood-bar").children().length;
                for (var i = 0; i < len; i++) {
                    if(scrollTop+250>=$("#floor"+i).offset().top) {
                        $(".lgb").eq(i).addClass("onlgb").siblings().removeClass("onlgb");
                    }
                }
            });
        },
        methods: {
            getUserInfo: function() {
                //获取用户名
                let param = {
                    msg: '123',
                };
                //发送get请求
                vc.http.apiGet('/user.getUserInfo',
                    param,
                    function(json, res) {
                        if (res.status == 200) {
                            var tmpUserInfo = JSON.parse(json);
                            vc.component.userInfo = tmpUserInfo;
                            //加个水印
                            if (tmpUserInfo.watermark == 'true') {
                                vc.watermark({ watermark_txt: vc.i18n('systemName') + ":" + tmpUserInfo.name });
                            }
                        }
                    },
                    function() {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadInformations: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 100
                    }
                };
                //发送get请求
                vc.http.apiGet('/system.initPlatformData',
                    param,
                    function(json, res) {
                        let _homePageInfo = JSON.parse(json);
                        $that.homePageInfo.total = _homePageInfo.total;
                        $that.homePageInfo.records = _homePageInfo.records;
                        $that.homePageInfo.informations = _homePageInfo.data.platformInformation;
                        $that.homePageInfo.prodClasses = _homePageInfo.data.platformProductClass;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _jumpToProductPage: function (_classId) {
                vc.jumpToPage("/page.html#/pages/plateform/product?hktId=" + _classId);
            },
            websiteAccessLog: function () {
                let user = vc.getData('/nav/getUserInfo');
                let param = '';
                if (user) {
                    param = {
                        loginName: user.name,
                        loginId: user.userId,
                        accessUrl: window.location.href,
                        loginState: '1'
                    }
                } else {
                    param = {
                        accessUrl: window.location.href,
                        loginState: '0'
                    }
                }
                vc.http.apiPost('websiteAccessLog.saveWebsiteAccessLog',
                    JSON.stringify(param), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            return;
                        }
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            }
        }
    });

})(window.vc);
